home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / SPPC / sppc.c < prev    next >
C/C++ Source or Header  |  1991-05-28  |  4KB  |  183 lines

  1. #include <Devices.h>
  2. #include <Files.h>
  3. #include <String.h>
  4.  
  5. #include "sppcinterface.h"
  6.  
  7. static short sppcrefnum = 0;        /* driver reference number */
  8.  
  9. OSErr getsppcref(void);            /* routine to get driver number */
  10.  
  11. OSErr SPPCRegister(unsigned char *myName, short *myRefNum)
  12. {
  13. OSErr rc;
  14. ParamBlockRec pbr;
  15. parmrec pmr, *pmrptr;
  16.  
  17.                         /* initialize for all calls */
  18. rc = getsppcref();
  19. if (rc != noErr) return(rc);
  20. memset(&pbr, 0, sizeof(ParamBlockRec));
  21. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  22. pmrptr = &pmr;
  23. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  24. memset (&pmr, 0, sizeof(parmrec));
  25.                         /* definitions for this call */
  26. pbr.cntrlParam.csCode = 1;
  27. pmr.name = myName;
  28. pmr.refptr = myRefNum;
  29. return(PBControl(&pbr, 0));
  30. }
  31.  
  32. OSErr SPPCDeRegister(short myRefNum)
  33. {
  34. OSErr rc;
  35. ParamBlockRec pbr;
  36. parmrec pmr, *pmrptr;
  37.  
  38.                         /* initialize for all calls */
  39. rc = getsppcref();
  40. if (rc != noErr) return(rc);
  41. memset(&pbr, 0, sizeof(ParamBlockRec));
  42. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  43. pmrptr = &pmr;
  44. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  45. memset (&pmr, 0, sizeof(parmrec));
  46.                         /* definitions for this call */
  47. pbr.cntrlParam.csCode = 2;
  48. pmr.refnum = myRefNum;
  49. return(PBControl(&pbr, 0));
  50. }
  51.  
  52. OSErr SPPCLookup(unsigned char *appName, short *itsRefNum)
  53. {
  54. OSErr rc;
  55. ParamBlockRec pbr;
  56. parmrec pmr, *pmrptr;
  57.  
  58.                         /* initialize for all calls */
  59. rc = getsppcref();
  60. if (rc != noErr) return(rc);
  61. memset(&pbr, 0, sizeof(ParamBlockRec));
  62. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  63. pmrptr = &pmr;
  64. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  65. memset (&pmr, 0, sizeof(parmrec));
  66.                         /* definitions for this call */
  67. pbr.cntrlParam.csCode = 3;
  68. pmr.name = appName;
  69. pmr.refptr = itsRefNum;
  70. return(PBControl(&pbr, 0));
  71. }
  72.  
  73. OSErr SPPCSend(short myRefNum, short toRefNum,
  74.               unsigned long replyId, Handle theMessage,
  75.               unsigned short msgLength, unsigned long *msgId)
  76. {
  77. OSErr rc;
  78. ParamBlockRec pbr;
  79. parmrec pmr, *pmrptr;
  80.  
  81.                         /* initialize for all calls */
  82. rc = getsppcref();
  83. if (rc != noErr) return(rc);
  84. memset(&pbr, 0, sizeof(ParamBlockRec));
  85. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  86. pmrptr = &pmr;
  87. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  88. memset (&pmr, 0, sizeof(parmrec));
  89.                         /* definitions for this call */
  90. pbr.cntrlParam.csCode = 4;
  91. pmr.refnum = myRefNum;
  92. pmr.refnum2 = toRefNum;
  93. pmr.replyid = replyId;
  94. pmr.msg = theMessage;
  95. pmr.msglen = msgLength;
  96. pmr.msgid = msgId;
  97. return(PBControl(&pbr, 0));
  98. }
  99.  
  100. OSErr SPPCGet(short myRefNum, short *fromRefNum,
  101.              unsigned long replyId, Handle theMessage,
  102.              unsigned short *msgLength, unsigned long *msgId,
  103.              unsigned long *replyIdPtr)
  104. {
  105. OSErr rc;
  106. ParamBlockRec pbr;
  107. parmrec pmr, *pmrptr;
  108.  
  109.                         /* initialize for all calls */
  110. rc = getsppcref();
  111. if (rc != noErr) return(rc);
  112. memset(&pbr, 0, sizeof(ParamBlockRec));
  113. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  114. pmrptr = &pmr;
  115. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  116. memset (&pmr, 0, sizeof(parmrec));
  117.                         /* definitions for this call */
  118. pbr.cntrlParam.csCode = 5;
  119. pmr.refnum = myRefNum;
  120. pmr.refptr = fromRefNum;
  121. pmr.replyid = replyId;
  122. pmr.msg = theMessage;
  123. pmr.msglenptr = msgLength;
  124. pmr.msgid = msgId;
  125. pmr.replyidptr = replyIdPtr;
  126. return(PBControl(&pbr, 0));
  127. }
  128.  
  129. OSErr SPPCClear(short myRefNum)
  130. {
  131. OSErr rc;
  132. ParamBlockRec pbr;
  133. parmrec pmr, *pmrptr;
  134.  
  135.                         /* initialize for all calls */
  136. rc = getsppcref();
  137. if (rc != noErr) return(rc);
  138. memset(&pbr, 0, sizeof(ParamBlockRec));
  139. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  140. pmrptr = &pmr;
  141. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  142. memset (&pmr, 0, sizeof(parmrec));
  143.                         /* definitions for this call */
  144. pbr.cntrlParam.csCode = 6;
  145. pmr.refnum = myRefNum;
  146. return(PBControl(&pbr, 0));
  147. }
  148.  
  149. OSErr SPPCDeleteMsg(unsigned long *msgId)
  150. {
  151. OSErr rc;
  152. ParamBlockRec pbr;
  153. parmrec pmr, *pmrptr;
  154.  
  155.                         /* initialize for all calls */
  156. rc = getsppcref();
  157. if (rc != noErr) return(rc);
  158. memset(&pbr, 0, sizeof(ParamBlockRec));
  159. pbr.cntrlParam.ioCRefNum = sppcrefnum;
  160. pmrptr = &pmr;
  161. memcpy(pbr.cntrlParam.csParam, &pmrptr, 4);
  162. memset (&pmr, 0, sizeof(parmrec));
  163.                         /* definitions for this call */
  164. pbr.cntrlParam.csCode = 7;
  165. pmr.msgid = msgId;
  166. return(PBControl(&pbr, 0));
  167. }
  168.  
  169. OSErr getsppcref(void)
  170. {
  171. ParamBlockRec pbr;
  172. OSErr rc;
  173.  
  174. if (sppcrefnum != 0) return(noErr);
  175.  
  176. memset(&pbr, 0, sizeof(ParamBlockRec));
  177. pbr.ioParam.ioNamePtr = "\p.SPPC";
  178. rc = PBOpen(&pbr, 0);
  179. if (rc == noErr) {
  180.     sppcrefnum = pbr.ioParam.ioRefNum;
  181.     }
  182. return(rc);
  183. }